<template>
	<div class="container">
		<div class="jx-container">
      <div class="select-type">
        <div class="item">
          <span style="width: 88px;">客户分组</span>
          <div class="right">
            <span v-for="(item, index) in $getJsonValue('客户分组')" :key="index" :class="params_list.group == item.val ? 'active' : ''" @click="selected(item)">{{item.label}}</span>
          </div>
        </div>
        <div class="item table-item">
          <div class="right">
            <div class="item-inline">
              <span>客户姓名</span>
              <el-input class="tel-value" v-model="params_list.username" placeholder="请输入客户姓名"></el-input>
            </div>
            <div class="item-inline">
              <span>客户手机号</span>
              <el-input class="tel-value" v-model="params_list.tel" placeholder="请输入客户手机号"></el-input>
            </div>
            <div class="item-inline">
              <span>车牌号</span>
              <el-input class="tel-value" v-model="params_list.no" placeholder="请输入车牌号"></el-input>
            </div>
            <div class="item-inline">
              <el-button class="jx-btn" type="primary" @click="search">搜索</el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="jx-table">
        <div class="title">
          <img class="icon" src="/static/img/icon-platform.png"/>
          待结算列表
        </div>
        <el-table :data="list" border style="width: 100%" v-loading="boo.loading">
          <el-table-column type="index" label="序列" width="60" align="center">
            <template slot-scope="scope">
              <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="group" label="所在组" align="center" width="150">
            <template slot-scope="scope">
              <el-button v-if="scope.row.group == '未指定'" @click="viewRow(scope.row)" type="text" size="small">{{scope.row.group}}</el-button>
              <span v-else>{{scope.row.group}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="客户姓名" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="tel" label="客户电话" align="center" width="120" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="address" label="所在地区" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="type" label="历史保单" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="sum" label="历史保单数量" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="time" label="最后一次订单时间" align="center" width="150" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column label="操作" align="center" width="150">
            <template slot-scope="scope">
              <el-button @click="addRow(scope.row)" type="text" size="small">新建营销单</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div v-if="list.length != 0" class="jx-pagination">
           <el-pagination @current-change="pageChange" @size-change="handleSizeChange" :current-page="params_list.page" :page-sizes="[10,50,100]" :page-size="params_list.size" layout="total, sizes, prev, pager, next, jumper"
            :total="other.allRow">
          </el-pagination>
        </div>
      </div>
    </div>
    <!-- 指定用户组 -->
    <el-dialog  :visible.sync="boo.showDialog" class="jx-dialog" width="65%">
      <div slot="title" class="header-title">
        <span class="title-name">指定用户组</span>
      </div>
      <el-form ref="form_other" :model="currentRow" :rules="rules" label-width="130px" class="jx-form">
        <div class="jx-detail">
          <div class="detail-item">
            <div class="item">
              <el-form-item label="选择用户组：" prop="group">
                <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全部</el-checkbox>
                <div style="margin: 15px 0;"></div>
                <el-checkbox-group v-model="currentRow.group" @change="handleCheckedCitiesChange">
                  <el-checkbox v-for="(item, index) in $getJsonValue('客户分组')" v-if="item.status == 1" :label="item.val" :key="index">{{item.label}}</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </div>
          </div>
        </div> 
      </el-form>
      <div class="btn-container">
        <el-button class="jx-btn" type="warning" @click="boo.showDialog = false">取消</el-button>
        <el-button class="jx-btn" type="primary" :loading="boo.saveing" @click="submitRow('form')">提交</el-button>
      </div>
    </el-dialog>
	</div>
</template>

<script>
  import list from 'static/json/client/list.json'
	export default {
		data() {
			return {
        boo: {
          loading: false,
          showDialog: false,
          saveing: false,
        },
        other: {
          allRow: 1,
        },
        list: list,
        currentRow: {group: []},
        params_list: {
          page: 1,
          size: 10,
          group: '',
          tel: '',
          username: '',
          no: '',
        },
        checkAll: false,
        isIndeterminate: true,
        rules: {
          group: [{ required: true, message: '请选择用户组', trigger: 'change' }],
        },
			}
		},
		mounted(){
      let _self = this
      _self.getList()
    },
		methods: {
      getList(){},
      selected(item){
        let _self = this
        _self.params_list.group = item.val
        _self.getList()
      },
      pageChange(val){
        let _self = this
        _self.params_list.page = val
        _self.getList()
      },
      handleSizeChange(val) {
        let _self = this
        _self.params_list.size = val
        _self.getList()
      },
      search(){
        let _self = this
      },
      addRow(){},
      viewRow(item){
        let _self = this
        _self.currentRow = {group: []}
        _self.boo.showDialog = true
      },
      handleCheckAllChange(val) {
        let _self = this
        _self.currentRow.group = val ? _self.$getJsonValue('客户分组') : [];
        _self.isIndeterminate = false;
      },
      handleCheckedCitiesChange(value) {
        let _self = this
        let checkedCount = value.length;
        _self.checkAll = checkedCount === _self.$getJsonValue('客户分组').length;
        _self.isIndeterminate = checkedCount > 0 && checkedCount < _self.$getJsonValue('客户分组').length;
      },
      submitRow(formName){
        let _self = this
				this.$refs[formName].validate((vaild)=>{
					if(vaild){  
            _self.boo.showDialog = false     
					}else{
						return false
					}
				})
      }
    }
	}

</script>
<style scoped lang="sass">
  .select-type .table-item .right span
    width: 78px
</style>
